function getCookie(name){    
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
}
function setCookie(c_name,value,exdays){
    //alert('funcSetCookie-'+c_name+'-'+value);
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + 
        ((exdays==null) ? "" : ("; expires="+exdate.toUTCString()));
    document.cookie=c_name + "=" + c_value+";path=/";
}
//click nav-tabs - start
//$(document).ready(function(){    
//    $('.mylist ul.nav-tabs > li> a').click(function(){        
//        var cook = $(this).attr('aria-controls');                        
//        var cookie=getCookie(cook);
//        alert();        
//        if(cookie==0){
//            setCookie(cook,'1','2000000');
//        }
//        else{
//            setCookie(cook,'0','2000000');
//        } 
//        $('li[role=presentation').each(function(){            
//            var cookother = $(this).find('a').attr('aria-controls');            
//            var cookieother=getCookie(cookother);
//            if(cook!=cookother)
//                setCookie(cookother,'1','2000000');                
//        });                        
//    });
//});
//click nav-tabs - end

//click sidebar - start
$(document).ready(function(){    
    $('.sidebar-nav > li > span .glyphicon-chevron-right').click(function(){        
        $(this).toggleClass('glyphicon-chevron-down');
        $(this).addClass('glyphicon-chevron-right');
        $(this).parent().parent().toggleClass('active');
        $(this).parent().parent().find('ul').toggleClass('hidden');
        var id = $(this).parent().attr('id');
        if(getCookie(id)==0 || getCookie(id)==null){
            setCookie(id,'1','2000000');    
        }else{
            setCookie(id,'0','2000000');
        }
        
                        
    });                     
//      $('.sidebar-nav li').hover(function(){
//        $(this).find('> a:first-child .background').animate({left:"0px"},"fast");
//        //$(this).find('> a:first-child .glyphicon').addClass('color-white');
//        $(this).find('> span:first-child .background').animate({left:"0px"},"fast");
//        //$(this).find('> span:first-child .glyphicon').addClass('color-white');
//    },function(){
//        $(this).find('> a:first-child .background').animate({left:"-40px"},"fast");
//        //$(this).find('> a:first-child .glyphicon').removeClass('color-white');
//        $(this).find('> span:first-child .background').animate({left:"-40px"},"fast");
//        //$(this).find('> span:first-child .glyphicon').removeClass('color-white');
//    });
});
//click sidebar - end

$(window).scroll(function() {
    var value = $(window).scrollTop()+' - '+$(window).height();
    $('#Ad_left').html(value);
    $('#Ad_left').html($(window).height());
   //if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
//       alert("near bottom!");
//   }
});

$(document).ready(function(){ 
    bkLib.onDomLoaded(function(){ 
        new nicEditors.allTextAreas(
            {buttonList : ['bold','italic','underline','strikeThrough','left','center','right','justify','indent','outdent','ol','ul'],
            maxHeight : 300}            
        );
        new nicEditors                	         
    });   
    var today = new Date();     
    var minDate = today;
/*    
    if(today.getHours()>17){
        today.setDate(today.getDate()+2);
    }else{
        today.setDate(today.getDate()+1);
    }    
    var minDate = today.getFullYear()+'/'+parseInt(today.getMonth()+1)+'/'+today.getDate();
*/                  
    $(".datepicker2").datetimepicker({        
        format: "Y-m-d",
        lang:'vi',
        i18n:{
          vi:{
           months:[
            'Tháng 1','Tháng 2','Tháng 3','Tháng 4',
            'Tháng 5','Tháng 6','Tháng 7','Tháng 8',
            'Tháng 9','Tháng 10','Tháng 11','Tháng 12',
           ],
           dayOfWeek:[
            "CN", "T2", "T3", "T4", 
            "T5", "T6", "T7",
           ]
          }
         },
        yearStart:"2010",
        yearEnd:"2020",
        timepicker:false,           
        minDate:minDate,              
    });        
});

$('#regisRegis').fancybox({
    type        : 'iframe',
	maxWidth	: 700,
	maxHeight	: 1200,
	fitToView	: false,
	width		: '70%',
	height		: '100%',
	autoSize	: false,
	closeClick	: false,
	openEffect	: 'none',
	closeEffect	: 'none'
});
$('#loginRegis').fancybox({
    type        : 'iframe',
	maxWidth	: 300,
	maxHeight	: 330,
	fitToView	: false,
	width		: '70%',
	height		: '70%',
	autoSize	: false,
	closeClick	: false,
	openEffect	: 'none',
	closeEffect	: 'none'
});
        
          window.fbAsyncInit = function() {
            FB.init({
              appId      : '1519082745020571',
              xfbml      : true,
              version    : 'v2.2'
            });
          };
                        
          (function(d, s, id){
             var js, fjs = d.getElementsByTagName(s)[0];
             if (d.getElementById(id)) {return;}
             js = d.createElement(s); js.id = id;
             js.src = "//connect.facebook.net/en_US/sdk.js";
             fjs.parentNode.insertBefore(js, fjs);
           }(document, 'script', 'facebook-jssdk'));
        